﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Admx_Generator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Admx_Generator.Tests
{
    [TestClass()]
    public class Test_SupportedOnList
    {
        private SupportedOnList _target = null;

        [TestInitialize()]
        public void Initialize()
        {
            this._target = new SupportedOnList("");
        }

        [TestMethod()]
        public void SupportedOnListTest()
        {
            SupportedOnList instance = new SupportedOnList(@"C:\Windows\PolicyDefinitions\Windows.admx");

            Assert.IsTrue(instance.SupportedonItems.Count != 0);
        }

        [TestMethod()]
        public void ExtractSupportedOnItemsTest()
        {
            Assert.IsTrue(this._target != null);
            string admxFile = @"C:\Windows\PolicyDefinitions\Windows.admx";

            List<SupportedOnItem> actual = this._target.ExtractSupportedOnItems(admxFile);
            Assert.IsTrue(actual.Count > 0);

            actual = this._target.ExtractSupportedOnItems("");
            Assert.IsTrue(actual.Count == 0);

            actual = this._target.ExtractSupportedOnItems(@"C:\Windows\PolicyDefinitions\null.admx");
            Assert.IsTrue(actual.Count == 0);
        }

        [TestMethod()]
        public void GetStringTableTest()
        {
            Assert.IsTrue(this._target != null);

            System.IO.FileInfo admxFile = new System.IO.FileInfo(@"C:\Windows\PolicyDefinitions\Windows.admx");
            Dictionary<string, string> actual = this._target.GetStringTable(admxFile);
            Assert.IsTrue(actual.Count != 0);

            admxFile = new System.IO.FileInfo(@"C:\Windows\PolicyDefinitions\null.admx");
            actual = this._target.GetStringTable(admxFile);
            Assert.IsTrue(actual.Count == 0);
            
            actual = this._target.GetStringTable(null);
            Assert.IsTrue(actual.Count == 0);
        }

        [TestMethod()]
        public void GetAdmlFileTest()
        {
            Assert.IsTrue(this._target != null);
            string admxFolder = @"C:\Windows\PolicyDefinitions";

            string expected = @"C:\Windows\PolicyDefinitions\fr-FR\AutoPlay.adml";
            string actual = this._target.GetAdmlFile(admxFolder, "AutoPlay.admx");
            Assert.AreEqual(expected, actual, "Valid Admx file path should returns the associated Adml file");

            expected = String.Empty;
            actual = this._target.GetAdmlFile(admxFolder, "AutoPly.admx");
            Assert.AreEqual(expected, actual, "A missing Admx file should returns String.Empty");
        }

        [TestMethod()]
        public void GetDisplayNameIDTest()
        {
            Assert.IsTrue(this._target != null);

            string expected = String.Empty;
            string actual = this._target.GetDisplayNameID(String.Empty);
            Assert.AreEqual(expected, actual, "An Empty string should returns an Empty string");

            expected = String.Empty;
            actual = this._target.GetDisplayNameID(null);
            Assert.AreEqual(expected, actual, "A null string should returns an Empty string");

            expected = "ThisIsAnID";
            actual = this._target.GetDisplayNameID("$(string.ThisIsAnID)");
            Assert.AreEqual(expected, actual, "An valid string should returns an valid ID");
        }
    }
}
